package leetcode.code1146;

import java.util.HashMap;
import java.util.Map;

public class SnapshotArray {

	Map<Integer, Integer> map;
	Map<Integer, Map<Integer, Integer>> snaps;
	int snap_id;

	public SnapshotArray(int length) {
		this.map = new HashMap<>();
		this.snap_id = 0;
		this.snaps = new HashMap<>();
	}

	public void set(int index, int val) {
		this.map.put(index, val);
	}

	public int snap() {
		this.snaps.put(snap_id, new HashMap<>(map));
		return snap_id++;
	}

	public int get(int index, int snap_id) {
		return this.snaps.getOrDefault(snap_id, new HashMap<>()).getOrDefault(index, 0);
	}

}
